package com.alks.function.service.impl.asyncImpl;

import com.alks.function.data.request.last.SoleSupportingInformationRequest;
import com.alks.function.mapper.last.LastStockMapping;
import com.alks.function.service.async.PcSoleAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;

/**
 * @author:xxxxx
 * @create: 2023-07-31 10:50
 * @Description: 面底配套异步查询
 */
@Service
public class PcSoleAsyncServiceImpl implements PcSoleAsyncService {
    @Autowired
    LastStockMapping lastStockMapping;
    @Override
    @Async
    public Future<List<Map<String, BigDecimal>>> getPcSupportingSum(SoleSupportingInformationRequest request) {
        List<Map<String, BigDecimal>> list = lastStockMapping.getPcSupportingSum(request);
        for (Map<String, BigDecimal> map : list) {
            if (map == null){
               continue;
            }
            Set<String> set = map.keySet();
            for (String s : set) {
                BigDecimal decimal = map.get(s);
                map.put(s,decimal.setScale(2, RoundingMode.HALF_UP));
            }
        }
        Future<List<Map<String, BigDecimal>>> future = new AsyncResult<>(list);
        return future ;
    }

    @Override
    @Async
    public Future<Long> getPcSoleSupportingTotal(SoleSupportingInformationRequest request) {
        return new AsyncResult<>(lastStockMapping.getPcSoleSupportingTotal(request));
    }
}
